package com.ruoyi.apis.service;

import com.ruoyi.apis.entity.DisplayEntity;
import com.ruoyi.apis.entity.LogoEntity;
import com.ruoyi.apis.entity.VideoEntity;
import com.ruoyi.apis.mapper.IDisplayMapper;
import com.ruoyi.apis.mapper.ILogoMapper;
import com.ruoyi.apis.mapper.IVideoMapper;
import com.ruoyi.apis.utils.ResponseUtils;
import com.ruoyi.apis.vo.DisplayVO;
import com.ruoyi.apis.vo.LogoVO;
import com.ruoyi.apis.vo.VideoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author Choi
 * @Date 2021/8/23
 */

@Service
public class IDisplayService {

    @Autowired
    private IDisplayMapper displayMapper;
    @Autowired
    private ILogoMapper logoMapper;
    @Autowired
    private IVideoMapper videoMapper;

    public List<DisplayVO> getDisplays(long cityId) {
        List<DisplayVO> displays = displayMapper.findByCityId(cityId);
        int size = displays.size();
        for (int i = 0; i < size; i++) {
            if (displays.get(i).getType() != null) {
                if (displays.get(i).getType() == 1) {
                    //LOGO
                    List<LogoEntity> logos = logoMapper.getByDisplayId(displays.get(i).getId());
                    displays.get(i).setLogos(LogoVO.getLogos(logos));
                } else {
                    //视频
                    VideoEntity video = videoMapper.getByDisplayId(displays.get(i).getId());
                    displays.get(i).setVideo(new VideoVO(video));
                }
            }
        }
        return displays;
    }
}
